package com.enlorenz.core.queue.transfer.imp;

import java.util.List;

import com.enlorenz.common.util.CommonUtils;
import com.enlorenz.core.queue.transfer.AbstractMessageQueue;


/**
 * 带有Wait等待的消息队列
 * 取出消息需要另外一个线程进行唤醒
 * @author lcb
 */
public class WaitMessageQueue<T> extends AbstractMessageQueue<T>{
	
	@Override
	protected void doAfterAdd() {
		synKey.notify();
	}

	@Override
	protected List<T> doListWhenListIsEmpty() {
		CommonUtils.wait(synKey);
		
		List<T> outputList=null;
		if (!messageList.isEmpty()) {
			outputList=popMessageList();
		}
		return outputList;
	}


	@Override
	protected T doObjectWhenListIsEmpty() {
		CommonUtils.wait(synKey);
		
		T message=null;
		if (!messageList.isEmpty()) {
			message=popMessage();
		}
		return message;
	}
}
